home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / bbs / termv4.6 / extras / source / gtlayout-source.lha / LT_CreateHandle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-18  |  14.3 KB  |  536 lines

  1. /*
  2. **    GadTools layout toolkit
  3. **
  4. **    Copyright © 1993-1996 by Olaf `Olsen' Barthel
  5. **        Freely distributable.
  6. **
  7. **    :ts=4
  8. */
  9.  
  10. #ifndef _GTLAYOUT_GLOBAL_H
  11. #include "gtlayout_global.h"
  12. #endif
  13.  
  14. LayoutHandle * LIBENT
  15. LT_CreateHandle(_REG(a0) struct Screen *Screen,_REG(a1) struct TextAttr *Font)
  16. {
  17.     return(LT_CreateHandleTags(Screen,
  18.         LH_Font,Font,
  19.     TAG_DONE));
  20. }
  21.  
  22.  
  23. /*****************************************************************************/
  24.  
  25.  
  26. LayoutHandle * __stdargs
  27. LT_CreateHandleTags(struct Screen *Screen,...)
  28. {
  29.     LayoutHandle    *Handle;
  30.     va_list          VarArgs;
  31.  
  32.     va_start(VarArgs,Screen);
  33.     Handle = LT_CreateHandleTagList(Screen,(struct TagItem *)VarArgs);
  34.     va_end(VarArgs);
  35.  
  36.     return(Handle);
  37. }
  38.  
  39.  
  40. /*****************************************************************************/
  41.  
  42.  
  43. /****** gtlayout.library/LT_CreateHandleTagList ******************************************
  44. *
  45. *   NAME
  46. *    LT_CreateHandleTagList -- Allocate auxilary data required by LT_New()
  47. *                              and LT_BuildA().
  48. *
  49. *   SYNOPSIS
  50. *    Handle = LT_CreateHandleTagList(Screen,Tags);
  51. *      D0                              A0    A1
  52. *
  53. *    LayoutHandle *LT_CreateHandleTagList(struct Screen *,struct TagItem *);
  54. *
  55. *    Handle = LT_CreateHandleTags(Screen,...);
  56. *
  57. *    struct LayoutHandle *LT_CreateHandleTags(struct Screen *,...);
  58. *
  59. *   FUNCTION
  60. *    Memory is allocated, tables are set up and data is collected
  61. *    on a screen a user interface is to be opened on. This
  62. *    involves calculating the screen font parameters.
  63. *
  64. *   INPUTS
  65. *    Screen - Pointer to the screen the user interface is to
  66. *        use. Passing NULL will cause the default public
  67. *        screen to be used.
  68. *
  69. *            NOTE: if NULL is passed the default public screen
  70. *                will stay locked until LT_DeleteHandle()
  71. *                is called.
  72. *
  73. *    Tags - Tag values to control certain aspects of the
  74. *        user interface created.
  75. *
  76. *
  77. *    Valid tags include:
  78. *
  79. *    LAHN_AutoActivate (BOOL) - Set to TRUE if you want the interface
  80. *        to always keep a string gadget active if possible. Hitting
  81. *        the return key will then cause the next following string
  82. *        gadget to get activated, either cycling through all the
  83. *        string gadgets available or stopping at the next string
  84. *        gadget to have the LAST_LastGadget attribute set.
  85. *        Default: TRUE
  86. *
  87. *    LAHN_RawKeyFilter (BOOL) - Discard unprocessed IDCMP_RAWKEY
  88. *        events.
  89. *        Default: TRUE
  90. *        (requires gtlayout.library v13 or higher)
  91. *
  92. *    LAHN_UserData (APTR) - Store user specific data in the
  93. *        LayoutHandle->UserData entry.
  94. *
  95. *            NOTE: This tag requires gtlayout.library v9 and the
  96. *                corresponding entry in the LayoutHandle exists
  97. *                only under gtlayout.library v9 and up. *NEVER*
  98. *                write to this entry, use LT_SetAttributes()
  99. *                instead.
  100. *
  101. *    LAHN_LocaleHook (struct Hook *) - The hook to call when
  102. *        locale string IDs are to be mapped to strings. The
  103. *        hook function is called with the following parameters:
  104. *
  105. *        String = HookFunc(struct Hook *Hook,struct LayoutHandle *Handle,
  106. *          D0                            A0                         A2
  107. *                          LONG ID)
  108. *                               A1
  109. *
  110. *        The function is to look up the string associated with the ID
  111. *        passed in and return the string.
  112. *        Default: no locale hook
  113. *
  114. *    LAHN_TextAttr (struct TTextAttr *) - The text font to use when
  115. *        creating the gadgets and objects.
  116. *        Default: Screen->Font
  117. *
  118. *    LAHN_CloningPermitted (BOOL) - If a window will not fit onto the
  119. *        screen the user interface is intended for, the layout engine
  120. *        will scale the interface data down while stepping down in
  121. *        font size. If all this fails, the engine will open a custom
  122. *        screen for the window; this process is called "cloning".
  123. *        The LAHN_CloningPermitted tag controls whether the engine will
  124. *        actually try to open the custom screen or just return NULL
  125. *        when LT_Build fails.
  126. *        Default: TRUE
  127. *
  128. *    LAHN_EditHook (struct Hook *) - You can specify a default string
  129. *        gadget editing hook to be used for all following string
  130. *        gadgets. Your hook should obey the same rules that apply
  131. *        to hooks passed via GTST_EditHook/GTIN_EditHook.
  132. *        Default: NULL
  133. *
  134. *    LAHN_ExactClone (BOOL) - This tag works in conjunction with the
  135. *        LAHN_CloningPermitted tag. By default the layout engine will
  136. *        try to replicate only the basic characteristics of the
  137. *        screen the window was intended to open on. This may result
  138. *        in a screen which uses less colours than the original
  139. *        screen. You can force the engine to make an almost exact
  140. *        clone of the original screen by passing the LAHN_ExactClone
  141. *        tag with a value of TRUE.
  142. *        Default: FALSE
  143. *
  144. *    LAHN_MenuGlyphs (BOOL) - This tag will make the layout engine
  145. *        fill in the AmigaGlyph and CheckGlyph entries of the
  146. *        LayoutHandle if running under Kickstart 3.0 or higher.
  147. *        The corresponding images will be scaled to fit the actual
  148. *        screen aspect ratio values and can later be used for
  149. *        menu layout.
  150. *        Default: FALSE
  151. *
  152. *    LAHN_Parent (struct Window *) - You can pass a pointer to the
  153. *        parent window of the window you intend to open using
  154. *        the user interface layout engine. The new window will
  155. *        open inside the boundaries of the parent window. If the
  156. *        size does not fit, it will be opened centered over the
  157. *        parent window.
  158. *        Default: NULL
  159. *
  160. *    LAHN_BlockParent (BOOL) - This tag works in conjunction with the
  161. *        LAHN_Parent tag. If in effect, will block the parent window
  162. *        via LT_LockWindow until the new window is closed, after
  163. *        which the parent window is unlocked again.
  164. *        Default: FALSE
  165. *
  166. *    LAHN_SimpleClone (BOOL) - This tag works in conjunction with the
  167. *        LAHN_CloningPermitted tag. It will make the layout engine
  168. *        forget most information about the original screen the
  169. *        user interface was intended for. In short, it will open a
  170. *        simple default screen for the interface.
  171. *        Default: FALSE
  172. *
  173. *    LAHN_ExitFlush (BOOL) - When the LayoutHandle is finally disposed
  174. *        of with LT_DeleteHandle() all variables maintained by the
  175. *        input handling code will be flushed. For example, if you
  176. *        would use the LA_STRPTR tag for STRING_KIND objects the
  177. *        last string gadget contents would be copied into the buffer
  178. *        pointed to by LA_STRPTR. If you do not want to use this
  179. *        feature, disable it with "LAHN_ExitFlush,FALSE".
  180. *        Default: TRUE
  181. *        (requires gtlayout.library v9 or higher)
  182. *
  183. *    LAHN_NoKeys (BOOL) - Use TRUE to tell the library not to pick
  184. *        keyboard shortcuts all on its own. This works like calling
  185. *        LT_New() for all objects with "LA_NoKey,TRUE,".
  186. *        (requires gtlayout.library v26 or higher)
  187. *
  188. *    LAHN_PubScreen (struct Screen *) - Pointer to public screen
  189. *        window is to open on. Must be locked and open until you call
  190. *        LT_Built().
  191. *
  192. *    LAHN_PubScreenName (STRPTR) - Name of public screen to open window
  193. *        on. The library will try to lock the named screen as soon as
  194. *        you call LT_CreateHandle.
  195. *
  196. *    LAHN_PubScreenFallBack (BOOL) - If the named public screen cannot
  197. *        be found and you ask for it, the library will lock the default
  198. *        public screen (default: TRUE).
  199. *
  200. *   RESULT
  201. *    Handle - Pointer to a LayoutHandle structure.
  202. *
  203. ******************************************************************************
  204. *
  205. */
  206.  
  207. LayoutHandle * LIBENT
  208. LT_CreateHandleTagList(_REG(a0) struct Screen *Screen,_REG(a1) struct TagItem *TagList)
  209. {
  210.     LayoutHandle    *Handle;
  211.     struct Screen    *PubScreen;
  212.     APTR             Pool;
  213.     ULONG             WA_ScreenTag;
  214.     BOOL             UnlockThePubScreen;
  215.  
  216. #ifdef DO_PICKSHORTCUTS
  217.     ObtainSemaphore(<P_KeySemaphore);
  218.  
  219.     if(!LTP_Keys[1])
  220.     {
  221.         UBYTE mapBuffer[2 * 3];
  222.         UBYTE remapBuffer[10];
  223.         LONG i;
  224.         struct InputEvent event;
  225.  
  226.         LTP_Keys[1] = <P_Keys[0][256];
  227.  
  228.         for(i = 32 ; i < 256; i++)
  229.         {
  230.             if(i == 128)
  231.                 i = 160;
  232.  
  233.             remapBuffer[0] = i;
  234.             remapBuffer[1] = 0;
  235.  
  236.             if(MapANSI(remapBuffer,1,mapBuffer,3,NULL) == 1)
  237.             {
  238.                 if(!(mapBuffer[1] & ~QUALIFIER_SHIFT))
  239.                 {
  240.                     event.ie_NextEvent            = NULL;
  241.                     event.ie_Class                = IECLASS_RAWKEY;
  242.                     event.ie_SubClass            = 0;
  243.                     event.ie_Code                 = mapBuffer[0];
  244.                     event.ie_Qualifier            = mapBuffer[1] & ~QUALIFIER_SHIFT;
  245.                     event.ie_position.ie_addr    = NULL;
  246.  
  247.                     if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  248.                         LTP_Keys[0][i] = remapBuffer[0];
  249.  
  250.                     event.ie_NextEvent            = NULL;
  251.                     event.ie_Class                = IECLASS_RAWKEY;
  252.                     event.ie_SubClass            = 0;
  253.                     event.ie_Code                 = mapBuffer[0];
  254.                     event.ie_Qualifier            = mapBuffer[1] | QUALIFIER_SHIFT;
  255.                     event.ie_position.ie_addr    = NULL;
  256.  
  257.                     if(MapRawKey(&event,remapBuffer,10,NULL) == 1)
  258.                         LTP_Keys[1][i] = remapBuffer[0];
  259.                 }
  260.             }
  261.         }
  262.     }
  263.  
  264.     ReleaseSemaphore(<P_KeySemaphore);
  265. #endif    /* DO_PICKSHORTCUTS */
  266.  
  267.     UnlockThePubScreen = TRUE;
  268.     WA_ScreenTag = WA_CustomScreen;
  269.  
  270.     if(!Screen)
  271.     {
  272.         if(PubScreen = (struct Screen *)GetTagData(LAHN_PubScreen,NULL,TagList))
  273.         {
  274.             UnlockThePubScreen = FALSE;
  275.             WA_ScreenTag = WA_PubScreen;
  276.             Screen = PubScreen;
  277.         }
  278.         else
  279.         {
  280.             STRPTR PubName;
  281.  
  282.             if(PubName = (STRPTR)GetTagData(LAHN_PubScreenName,NULL,TagList))
  283.             {
  284.                 if(!(PubScreen = LockPubScreen(PubName)))
  285.                 {
  286.                     if(!GetTagData(LAHN_PubScreenFallBack,TRUE,TagList))
  287.                         return(NULL);
  288.                 }
  289.             }
  290.             else
  291.                 PubScreen = NULL;
  292.  
  293.             if(!PubScreen)
  294.                 PubScreen = LockPubScreen(NULL);
  295.  
  296.             if(!PubScreen)
  297.                 return(NULL);
  298.             else
  299.             {
  300.                 Screen = PubScreen;
  301.                 WA_ScreenTag = WA_PubScreen;
  302.             }
  303.         }
  304.     }
  305.     else
  306.     {
  307.         PubScreen = NULL;
  308.         UnlockThePubScreen = FALSE;
  309.     }
  310.  
  311.     if(Pool = AsmCreatePool(MEMF_PUBLIC | MEMF_ANY | MEMF_CLEAR,1024,1024,SysBase))
  312.     {
  313.         if(Handle = AsmAllocPooled(Pool,sizeof(LayoutHandle),SysBase))
  314.         {
  315.             struct TagItem    *List,
  316.                             *Entry;
  317.             BOOL             MenuGlyphs;
  318.  
  319.             MenuGlyphs = FALSE;
  320.  
  321.             Handle->Pool                = Pool;
  322.             Handle->Screen                = Screen;
  323.             Handle->PubScreen            = PubScreen;
  324.             Handle->PointBack            = Handle;
  325.             Handle->GroupID                = PHANTOM_GROUP_ID;
  326.  
  327.             Handle->WA_ScreenTag        = WA_ScreenTag;
  328.             Handle->UnlockPubScreen        = UnlockThePubScreen;
  329.  
  330.             Handle->ExitFlush            = TRUE;
  331.             Handle->RawKeyFilter        = TRUE;
  332. #ifdef DO_CLONING
  333.             Handle->CloningPermitted    = TRUE;
  334. #endif
  335.             Handle->StandardEditHook    = &Handle->DefaultEditHook;
  336.  
  337.             List = TagList;
  338.  
  339.             while(Entry = NextTagItem(&List))
  340.             {
  341.                 switch(Entry->ti_Tag)
  342.                 {
  343.                     case LH_Font:
  344.  
  345.                         Handle->InitialTextAttr = (struct TextAttr *)Entry->ti_Data;
  346.                         break;
  347.  
  348.                     case LH_MenuGlyphs:
  349.  
  350.                         MenuGlyphs = Entry->ti_Data;
  351.                         break;
  352.  
  353.                     case LH_Parent:
  354.  
  355.                         Handle->Parent = (struct Window *)Entry->ti_Data;
  356.                         break;
  357.  
  358.                     case LH_BlockParent:
  359.  
  360.                         Handle->BlockParent = Entry->ti_Data;
  361.                         break;
  362.  
  363.                     case LH_ExitFlush:
  364.  
  365.                         Handle->ExitFlush = Entry->ti_Data;
  366.                         break;
  367.  
  368.                     case LH_UserData:
  369.  
  370.                         Handle->UserData = (APTR)Entry->ti_Data;
  371.                         break;
  372.  
  373.                     case LH_RawKeyFilter:
  374.  
  375.                         Handle->RawKeyFilter = Entry->ti_Data;
  376.                         break;
  377.  
  378.                     case LH_AutoActivate:
  379.  
  380.                         Handle->AutoActivate = Entry->ti_Data;
  381.                         break;
  382.  
  383.                     case LH_LocaleHook:
  384.  
  385.                         Handle->LocaleHook = (struct Hook *)Entry->ti_Data;
  386.                         break;
  387.  
  388.                     case LH_EditHook:
  389.  
  390.                         Handle->StandardEditHook = (struct Hook *)Entry->ti_Data;
  391.                         break;
  392.  
  393.                     case LAHN_NoKeys:
  394.  
  395.                         Handle->NoKeys = Entry->ti_Data;
  396.                         break;
  397. #ifdef DO_CLONING
  398.                     case LH_CloningPermitted:
  399.  
  400.                         Handle->CloningPermitted = Entry->ti_Data;
  401.                         break;
  402.  
  403.                     case LH_SimpleClone:
  404.  
  405.                         if(Handle->SimpleClone = Entry->ti_Data)
  406.                             Handle->ExactClone = FALSE;
  407.  
  408.                         break;
  409.  
  410.                     case LH_ExactClone:
  411.  
  412.                         if(Handle->ExactClone = Entry->ti_Data)
  413.                             Handle->SimpleClone = FALSE;
  414.  
  415.                         break;
  416. #endif
  417.                 }
  418.             }
  419.  
  420. #ifdef DO_FRACTION_KIND
  421.             Handle->FracEditHook.h_Entry    = (HOOKFUNC)LTP_FracEditRoutine;
  422.             Handle->FracEditHook.h_Data     = Handle;
  423. #endif
  424.  
  425. #ifdef DO_PASSWORD_KIND
  426.             Handle->PasswordEditHook.h_Entry    = (HOOKFUNC)LTP_PasswordEditRoutine;
  427.             Handle->PasswordEditHook.h_Data        = Handle;
  428. #endif
  429.  
  430.             Handle->DefaultEditHook.h_Entry    = (HOOKFUNC)LTP_DefaultEditRoutine;
  431.             Handle->DefaultEditHook.h_Data    = Handle;
  432.  
  433.             Handle->BackfillHook.h_Entry    = (HOOKFUNC)LTP_BackfillRoutine;
  434.             Handle->BackfillHook.h_Data     = Handle;
  435.  
  436. #ifdef DO_HEXHOOK
  437.             Handle->HexEditHook.h_Entry     = (HOOKFUNC)LTP_HexEditRoutine;
  438.             Handle->HexEditHook.h_Data        = Handle;
  439. #endif
  440.  
  441.             if(Handle->DrawInfo = GetScreenDrawInfo(Screen))
  442.             {
  443.                 LONG i;
  444.  
  445.                 Handle->TextPen            = Handle->DrawInfo->dri_Pens[TEXTPEN];
  446.                 Handle->BackgroundPen    = Handle->DrawInfo->dri_Pens[BACKGROUNDPEN];
  447.                 Handle->ShinePen        = Handle->DrawInfo->dri_Pens[SHINEPEN];
  448.                 Handle->ShadowPen        = Handle->DrawInfo->dri_Pens[SHADOWPEN];
  449.                 Handle->AspectX            = Handle->DrawInfo->dri_Resolution.X;
  450.                 Handle->AspectY            = Handle->DrawInfo->dri_Resolution.Y;
  451.  
  452.                 if(Handle->BackgroundPen)
  453.                 {
  454.                     InitRastPort(&Handle->BackfillRastPort);
  455.                     SetAPen(&Handle->BackfillRastPort,Handle->BackgroundPen);
  456.                 }
  457.  
  458.                 if(V39 && MenuGlyphs)
  459.                 {
  460.                     LONG i,Size,Width,Height = Handle->DrawInfo->dri_Font->tf_Baseline + 2;
  461.                     struct Image **Glyphs[2];
  462.  
  463.                     Glyphs[0] = &Handle->AmigaGlyph;
  464.                     Glyphs[1] = &Handle->CheckGlyph;
  465.  
  466.                     if(Screen->Flags & SCREENHIRES)
  467.                         Size = SYSISIZE_MEDRES;
  468.                     else
  469.                         Size = SYSISIZE_LOWRES;
  470.  
  471.                     for(i = 0 ; i < 2 ; i++)
  472.                     {
  473.                         if(i)
  474.                             Width = (Height * Handle->AspectY) / Handle->AspectX;
  475.                         else
  476.                             Width = (Height * 3 * Handle->AspectY) / (2 * Handle->AspectX);
  477.  
  478.                         if(!(*Glyphs[i] = NewObject(NULL,SYSICLASS,
  479.                             SYSIA_DrawInfo, Handle->DrawInfo,
  480.                             SYSIA_Size,        Size,
  481.                             SYSIA_Which,    i ? MENUCHECK : AMIGAKEY,
  482.                             IA_Width,        Width,
  483.                             IA_Height,        Height,
  484.                         TAG_DONE)))
  485.                         {
  486.                             DisposeObject(*Glyphs[0]);
  487.                             *Glyphs[0] = NULL;
  488.  
  489.                             break;
  490.                         }
  491.                     }
  492.                 }
  493.  
  494.                 for(i = 0 ; i < Handle->DrawInfo->dri_NumPens ; i++)
  495.                 {
  496.                     if(Handle->DrawInfo->dri_Pens[i] > Handle->MaxPen)
  497.                         Handle->MaxPen = Handle->DrawInfo->dri_Pens[i];
  498.                 }
  499.  
  500.                 if(Handle->VisualInfo = GetVisualInfoA(Screen,NULL))
  501.                 {
  502.                     InitRastPort(&Handle->RPort);
  503.  
  504.                     if(LTP_GlyphSetup(Handle,Handle->InitialTextAttr))
  505.                     {
  506. #ifdef DO_PICKSHORTCUTS
  507.                         memset(Handle->Keys,TRUE,256);
  508.  
  509.                         for(i = 0 ; i < 256 ; i++)
  510.                         {
  511.                             if(i != 32 && i != 160)
  512.                             {
  513.                                 if(LTP_Keys[0][i])
  514.                                     Handle->Keys[LTP_Keys[0][i]] = FALSE;
  515.  
  516.                                 if(LTP_Keys[1][i])
  517.                                     Handle->Keys[LTP_Keys[1][i]] = FALSE;
  518.                             }
  519.                         }
  520. #endif
  521.                         return(Handle);
  522.                     }
  523.                 }
  524.             }
  525.  
  526.             LT_DeleteHandle(Handle);
  527.         }
  528.         else
  529.             AsmDeletePool(Pool,SysBase);
  530.     }
  531.     else
  532.         UnlockPubScreen(NULL,PubScreen);
  533.  
  534.     return(NULL);
  535. }
  536.